using System;
using System.Runtime.Serialization;
using MiniStock.Entities.Common;
using MiniStock.Entities.Common.Events;

namespace MiniStock.Entities.Stock.Events.Customer
{
    [DataContract]
    [KnownType(typeof(AddressChangeEvent))]
    [KnownType(typeof(ChangeContactPersonEvent))]
    [KnownType(typeof(CreateCustomerEvent))]
    [KnownType(typeof(ChangeCustomerNameEvent))]
    [KnownType(typeof(ChangeHQAddressEvent))]
    [KnownType(typeof(ChangeShippingAddressEvent))]
    public abstract class CustomerEventBase : EntityEventBase
    {
        [DataMember]
        public Guid Id { get; set; }

        public override void ApplyTo(EntityBase entity)
        {
            if(entity != null && !(entity is Stock.Customer))
                throw new ApplicationException("Event is only valid for customers");
        }

        public override bool IsConstructionMessage
        {
            get { return this is CreateCustomerEvent; }
        }

        public override string GetEntityHash()
        {
            return "Customer|" + Id;
        }

        public override Type GetEntityType()
        {
            return typeof (Stock.Customer);
        }
    }
}